package com.kk.interpreter;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

/**
 * @author o_o
 * @date 2022-06-19
 */
public class Client {
    public static void main(String[] args) {
        String expr = getExpr();
        HashMap<String, Integer> value = getValue(expr);
        Calculator calculator = new Calculator(expr);
        System.out.println("运算结果：" + expr + " = " + calculator.run(value));
    }

    //获得表达式
    private static String getExpr() {
        System.out.println("请输入表达式：");
        try {
            return new BufferedReader(new InputStreamReader(System.in)).readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    //获得映射值
    private static HashMap<String, Integer> getValue(String expr) {
        HashMap<String, Integer> hashMap = new HashMap<>();
        for (char c : expr.toCharArray()) {
            if (c != '+' && c != '-') {
                hashMap.put(String.valueOf(c), Integer.valueOf(String.valueOf(c)));
            }
        }
        return hashMap;
    }

}
